package bu.met.cs664;

/**
 * Abstract class to identify players and to make sure they are capable of making a move.
 */
public abstract class Player {

	// Constants to differentiate players
	static final int PLAYER_X = 0;
	static final int PLAYER_O = 1;
	
	// The player identifier
    private final int id;

    /**
     * Constructor
     * 
     * @param	id	the player's ID
     */
    Player(int id) {
		assert((id == PLAYER_X) || (id == PLAYER_O));
		
    	this.id = id;
    }
    
    /**
     * Is this player X?
     * 
     * @return true if X, false otherwise
     */
    public boolean isPlayerX() {
    	return (id == PLAYER_X);
    }
    
    /**
     * Is this player O?
     * 
     * @return	true if O, false otherwise
     */
    public boolean isPlayerO() {
    	return (id == PLAYER_O);
    }
    
    @Override
    public String toString() {
    	return (isPlayerX()) ? "X" : "O";
    }
    
    /**
     * Returns a character to represent this player.
     * 
     * @return	the player's character
     */
    public char toChar() {
    	return (isPlayerX()) ? 'X' : 'O';
    }
	
    /**
     * Get the next move using the derived class's strategy.
     * 
     * @param	board	the current play board
     * 
     * @return	a zero-based board square selection
     */
	public abstract int nextMove(Board board);
}
